package com.message.Volcengine_ai_API.controller;
import cn.hutool.json.JSONObject;
import com.base.annotation.SysLog;
import com.base.helper.Result;
import com.message.Volcengine_ai_API.service.VolcenginePictureService;
import com.message.Volcengine_ai_API.vo.VolAgeChangeVo;
import com.message.Volcengine_ai_API.vo.VolEmotionPortraitVo;
import com.message.Volcengine_ai_API.vo.VolHairStyleVo;
import com.message.Volcengine_ai_API.vo.VolThreeDGameCartoonVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.Map;

@Api(tags = "火山api调用")
@RestController
@RequestMapping("/VolcenginePicture")
public class VolcenginePictureController {
    @Value("${external.resource.dir}")
    private String externalResourceDir;
    @Autowired
    private VolcenginePictureService volcenginePictureService;
    @SysLog(action = "VolcenginePicture:TextToImage", value = "火山引擎ai图像生成:文生图")
    @ApiOperation(value = "文生图",notes = "火山引擎ai图像生成")
    @RequestMapping(value="TextToImage",method = {RequestMethod.POST})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "text", value = "图片的文本描述", paramType = "query"),
            @ApiImplicitParam(name = "add_logo", value = "是否添加logo，默认不添加", paramType = "query"),
            @ApiImplicitParam(name = "schedule_conf", value = "美感版选1，标准版其余数字", paramType = "query"),
            @ApiImplicitParam(name = "position", value = "水印位置", paramType = "query"),
            @ApiImplicitParam(name = "logo_text_content", value = "水印内容", paramType = "query"),
    })
    public Result<Object> TextToImage(@RequestParam("text")String text,
                                      @RequestParam(value = "add_logo",required = false) Boolean add_logo,
                                      @RequestParam(value = "schedule_conf",defaultValue = "0")  Integer schedule_conf,
                                      @RequestParam(value = "position",required=false) Integer position,
                                      @RequestParam(value = "logo_text_content",required=false) String logo_text_content) throws Exception {
            return new Result<>(true, volcenginePictureService.TextToImage(text,add_logo,schedule_conf,position,logo_text_content));
    }
    @SysLog(action = "VolcenginePicture:emotionPortrait", value = "火山引擎ai图像生成:表情编辑")
    @ApiOperation(value = "表情编辑", notes = "火山引擎ai图像生成")
    @RequestMapping(value = "emotionPortrait", method = {RequestMethod.POST})
    public Result emotionPortrait(@Valid @RequestBody VolEmotionPortraitVo volEmotionPortraitVo) throws Exception {
        Map response = volcenginePictureService.emotionPortrait(volEmotionPortraitVo);
        JSONObject jsonObject = new JSONObject(response.get("body").toString());
        return new Result<>(true, jsonObject);
    }

    @SysLog(action = "VolcenginePicture:hairStyle", value = "火山引擎ai图像生成:发型编辑")
    @ApiOperation(value = "发型编辑", notes = "火山引擎ai图像生成")
    @RequestMapping(value = "hairStyle", method = {RequestMethod.POST})
    public Result hairStyle(@Valid @RequestBody VolHairStyleVo volHairStyleVo) throws Exception {
        Map response = volcenginePictureService.hairStyle(volHairStyleVo);
        JSONObject jsonObject = new JSONObject(response.get("body").toString());
        return new Result<>(true, jsonObject);
    }

    @SysLog(action = "VolcenginePicture:ageChange", value = "火山引擎ai图像生成:人像年龄变换")
    @ApiOperation(value = "人像年龄变换", notes = "火山引擎ai图像生成")
    @RequestMapping(value = "ageChange", method = {RequestMethod.POST})
    public Result ageChange(@Valid @RequestBody VolAgeChangeVo volAgeChangeVo) throws Exception {
        Map response = volcenginePictureService.ageChange(volAgeChangeVo);
        JSONObject jsonObject = new JSONObject(response.get("body").toString());
        return new Result<>(true, jsonObject);
    }


    @SysLog(action = "VolcenginePicture:threeDGameCartoon", value = "火山引擎ai图像生成:3D游戏特效")
    @ApiOperation(value = "3D游戏特效", notes = "火山引擎ai图像生成")
    @RequestMapping(value = "threeDGameCartoon", method = {RequestMethod.POST})
    public Result threeDGameCartoon(@Valid @RequestBody VolThreeDGameCartoonVo volThreeDGameCartoonVo) throws Exception {
        Map response = volcenginePictureService.threeDGameCartoon(volThreeDGameCartoonVo);
        JSONObject jsonObject = new JSONObject(response.get("body").toString());
        return new Result<>(true, jsonObject);
    }
    @SysLog(action = "VolcenginePicture:JPCartoon", value = "火山引擎ai图像生成:人像漫画风")
    @ApiOperation(value = "人像漫画风",notes = "火山引擎ai图像生成")
    @RequestMapping(value="JPCartoon",method = {RequestMethod.POST})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "image_url", value = "图片", paramType = "query"),
            @ApiImplicitParam(name = "cartoon_type", value = "卡通类型", paramType = "query"),
    })
    public Result<Object> JPCartoon(@RequestParam("image_url") MultipartFile image,
                                      @RequestParam("cartoon_type") String cartoon_type) throws Exception {
        return new Result<>(true, volcenginePictureService.JPCartoon(image,cartoon_type));
    }

    @SysLog(action = "VolcenginePicture:SinglePhoto", value = "火山引擎ai图像生成:单图写真")
    @ApiOperation(value = "单图写真",notes = "火山引擎ai图像生成")
    @RequestMapping(value="SinglePhoto",method = {RequestMethod.POST})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "req_key", value = "风格：\n" +
                    "img2img_photoverse_american_comics（美漫风格）\n" +
                    "img2img_photoverse_executive_ID_photo（商务证件照）\n" +
                    "img2img_photoverse_3d_weird(3d人偶)\n" +
                    "img2img_photoverse_cyberpunk(赛博朋克)\n" +
                    "img2img_xiezhen_gubao(古堡)\n" +
                    "img2img_xiezhen_babi_niuzai(芭比牛仔)\n" +
                    "img2img_xiezhen_bathrobe(浴袍风格)\n"+
                    "img2img_xiezhen_butterfly_machine(蝴蝶机械)\n"+
                    "img2img_xiezhen_zhichangzhengjianzhao(职场证件照)\n"+
                    "img2img_xiezhen_christmas(圣诞)\n"+
                    "img2img_xiezhen_dessert(美式甜点师)\n"+
                    "img2img_xiezhen_old_money(old money)\n"+
                    "img2img_xiezhen_school(最美校园)\n", paramType = "query"),
            @ApiImplicitParam(name = "binary_data_base64", value = "图片", paramType = "query")
    })
    public Result<Object> SinglePhoto( @RequestParam("req_key") String req_key, @RequestParam("binary_data_base64") String binary_data_base64)throws Exception{
        return new Result<>(true, volcenginePictureService.SinglePhoto(req_key,binary_data_base64));
    }

    @SysLog(action = "VolcenginePicture:SmudgeEditing", value = "火山引擎ai图像生成:涂抹编辑")
    @ApiOperation(value = "涂抹编辑",notes = "火山引擎ai图像生成")
    @RequestMapping(value="SmudgeEditing",method = {RequestMethod.POST})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "binary_data_base64", value = "图片数组", paramType = "query"),@ApiImplicitParam(name = "custom_prompt", value = "生成图像提示词", paramType = "query")
    })
    public Result<Object> SmudgeEditing( @RequestParam("binary_data_base64") String[] binary_data_base64,@RequestParam("custom_prompt") String custom_prompt)throws Exception{
        return new Result<>(true, volcenginePictureService.SmudgeEditing(binary_data_base64,custom_prompt));
    }

    @SysLog(action = "VolcenginePicture:SmearElimination", value = "火山引擎ai图像生成:涂抹消除")
    @ApiOperation(value = "涂抹消除",notes = "火山引擎ai图像生成")
    @RequestMapping(value="SmearElimination",method = {RequestMethod.POST})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "binary_data_base64", value = "图片数组", paramType = "query")
    })
    public Result<Object> SmearElimination( @RequestParam("binary_data_base64") String[] binary_data_base64)throws Exception{
        return new Result<>(true, volcenginePictureService.SmearElimination(binary_data_base64));
    }
    @SysLog(action = "VolcenginePicture:PortraitMatting", value = "火山引擎ai图像生成:人像抠图")
    @ApiOperation(value = "人像抠图",notes = "火山引擎ai图像生成")
    @RequestMapping(value="PortraitMatting",method = {RequestMethod.POST})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "image_base64", value = "图片", paramType = "query")
    })
    public Result<Object> PortraitMatting(@RequestParam("image_base64") String image_base64) throws Exception {
        return new Result<>(true, volcenginePictureService.PortraitMatting(image_base64));
    }

}
